/*************************************************************************
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: IBM Corporation
 *
 *  Copyright: 2008 by IBM Corporation
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
/*************************************************************************
 * @file 
 *  For LWP filter architecture prototype
 ************************************************************************/
/*************************************************************************
 * Change History
 Jan 2005			Created
 ************************************************************************/


#include "lwpparastyle.hxx"
#include "lwpfilehdr.hxx"
#include "lwpoverride.hxx"
#include "lwpparaborderoverride.hxx"
#include "lwpbreaksoverride.hxx"
#include "lwpnumberingoverride.hxx"
#include "lwptaboverride.hxx"
#include "lwpbackgroundoverride.hxx"
#include "xfilter/xfdefs.hxx"
#include "xfilter/xfparastyle.hxx"
#include "xfilter/xfborders.hxx"
#include "lwpfont.hxx"
#include "lwpfoundry.hxx"
#include "lwppiece.hxx"
#include "lwpshadow.hxx"
#include "lwpborderstuff.hxx"
#include "lwpmargins.hxx"
#include "lwptabrack.hxx"

#include "lwpsilverbullet.hxx"


LwpParaStyle::LwpParaStyle(LwpObjectHeader& objHdr, LwpSvStream* pStrm) :
LwpTextStyle(objHdr, pStrm), m_pKinsokuOptsOverride(new LwpKinsokuOptsOverride),
m_pBulletOverride(new LwpBulletOverride)
{
}

LwpParaStyle::~LwpParaStyle()
{
	if (m_pKinsokuOptsOverride)
	{
		delete m_pKinsokuOptsOverride;
	}
	
	if (m_pBulletOverride)
	{
		delete m_pBulletOverride;
	}
}

void LwpParaStyle::Read()
{
	LwpTextStyle::Read();

	if (LwpFileHeader::m_nFileRevision < 0x000B)
	{
		// read many overrides
		LwpAlignmentOverride	aAlignOverride;
		aAlignOverride.Read(m_pObjStrm);

		LwpSpacingOverride	aSpacingOverride;
		aSpacingOverride.Read(m_pObjStrm);

		LwpIndentOverride		aIndentOverride;
		aIndentOverride.Read(m_pObjStrm);

		LwpParaBorderOverride	aPBOverride;
		aPBOverride.Read(m_pObjStrm);

		LwpBreaksOverride	aBreaksOverride;
		aBreaksOverride.Read(m_pObjStrm);

		LwpNumberingOverride	aNumberingOverride;
		aNumberingOverride.Read(m_pObjStrm);

		LwpTabOverride		aTabOverride;
		aTabOverride.Read(m_pObjStrm);
		
	}
	else
	{
		m_AlignmentStyle.ReadIndexed(m_pObjStrm);
		m_SpacingStyle.ReadIndexed(m_pObjStrm);
		m_IndentStyle.ReadIndexed(m_pObjStrm);
		m_BorderStyle.ReadIndexed(m_pObjStrm);
		m_BreaksStyle.ReadIndexed(m_pObjStrm);
		m_NumberingStyle.ReadIndexed(m_pObjStrm);
		m_TabStyle.ReadIndexed(m_pObjStrm);
	
		m_pKinsokuOptsOverride->Read(m_pObjStrm);
		m_pBulletOverride->Read(m_pObjStrm);

		if (m_pObjStrm->CheckExtra())
		{
			m_BackgroundStyle.ReadIndexed(m_pObjStrm);
			m_pObjStrm->SkipExtra(); 
		}

		
	}
}

void	LwpParaStyle::Apply(XFParaStyle *pParaStyle)
{
	assert(pParaStyle);
	LwpVirtualPiece	*pPiece = NULL;
	//alignment:
	pPiece = (LwpVirtualPiece*)m_AlignmentStyle.obj();
	if( pPiece )
	{
		LwpAlignmentOverride	*pAlign = (LwpAlignmentOverride*)pPiece->GetOverride();
		if( pAlign )
                ApplyAlignment(pParaStyle,pAlign);
	}

	//don't known top and bottom indent now.
	pPiece = (LwpVirtualPiece*)m_IndentStyle.obj();
	if( pPiece )
	{
		LwpIndentOverride	*pIndent = (LwpIndentOverride*)pPiece->GetOverride();
		if( pIndent )
		{
			if (!m_pBulletOverride->IsInValid())//Add by ,for remove bullet indent in named bullet style
			{
				LwpIndentOverride* pNewIndent = new LwpIndentOverride;
                *pNewIndent = *pIndent;
				pNewIndent->SetMFirst(0);
				pNewIndent->SetMRest(0);
				ApplyIndent(NULL,pParaStyle,pNewIndent);
				delete pNewIndent;
			}
			else
				ApplyIndent(NULL,pParaStyle,pIndent);
		}
	}
	//shadow & borders.
	pPiece = (LwpVirtualPiece*)m_BorderStyle.obj();
	if( pPiece )
	{
		LwpParaBorderOverride *pBorder = (LwpParaBorderOverride*)pPiece->GetOverride();
		if( pBorder )
		{
			this->ApplyParaBorder(pParaStyle, pBorder);
		}
	}

    pPiece = (LwpVirtualPiece*)m_SpacingStyle.obj();
    if (pPiece)
    {
        LwpSpacingOverride	*pSpacing = (LwpSpacingOverride*)pPiece->GetOverride();
        if( pSpacing)
            ApplySpacing(NULL,pParaStyle,pSpacing);        
    }
    
	//paragraph background.
	pPiece = (LwpVirtualPiece*)m_BackgroundStyle.obj();
	if( pPiece )
	{
		LwpBackgroundOverride *pBack = (LwpBackgroundOverride*)pPiece->GetOverride();
		if( pBack )
		{
			LwpColor color = pBack->GetBackColor();
			XFColor aXFColor( color.To24Color() );
			pParaStyle->SetBackColor( aXFColor );
		}
	}

	// 01/28/2005
	//add tab style
	pPiece = (LwpVirtualPiece*)m_TabStyle.obj();
	if( pPiece	)
	{
		LwpTabOverride *pTab=(LwpTabOverride*)pPiece->GetOverride();
		if(pTab)
		{
			ApplyTab(pParaStyle,pTab);
		}		
	}
	//add by  2005/02/16
	pPiece = (LwpVirtualPiece*)m_BreaksStyle.obj();
	if( pPiece	)
	{
		LwpBreaksOverride *pBreak=(LwpBreaksOverride*)pPiece->GetOverride();
		if(pBreak)
		{
			ApplyBreaks(pParaStyle,pBreak);
		}		
	}
	//add end
}

void LwpParaStyle::ApplySubBorder(LwpBorderStuff* pBorderStuff, LwpBorderStuff::BorderType eType, XFBorders* pXFBorders)
{
	enumXFBorder eXFBorderSide = enumXFBorderNone;
	switch (eType)
	{
	case LwpBorderStuff::LEFT:
		eXFBorderSide = enumXFBorderLeft;
		break;
	case LwpBorderStuff::RIGHT:
		eXFBorderSide = enumXFBorderRight;
		break;
	case LwpBorderStuff::TOP:
		eXFBorderSide = enumXFBorderTop;
		break;
	case LwpBorderStuff::BOTTOM:
		eXFBorderSide = enumXFBorderBottom;
		break;
	}
	
	LwpColor	aColor = pBorderStuff->GetSideColor(eType);
	float		fWidth = pBorderStuff->GetSideWidth(eType);
	sal_uInt16	nType = pBorderStuff->GetSideType(eType);

	switch (nType)
	{
	default://fall through!
	case 0x14: //single fall through!
	case 0x17: //treble
		pXFBorders->SetWidth(eXFBorderSide, fWidth);
		break;
	case 0x15: //double , fall through!
	case 0x16: //thick double
		pXFBorders->SetDoubleLine(eXFBorderSide, sal_True, sal_False);
		pXFBorders->SetWidthOutter(eXFBorderSide, static_cast<float>(fWidth*0.333));
		pXFBorders->SetWidthSpace(eXFBorderSide, static_cast<float>(fWidth*0.334));
		pXFBorders->SetWidthInner(eXFBorderSide, static_cast<float>(fWidth*0.333));
//		pXFBorders->SetWidth(eXFBorderSide, fWidth);
		break;
	case 0x18: //thick-thin
		pXFBorders->SetDoubleLine(eXFBorderSide, sal_True, sal_False);
		pXFBorders->SetWidthOutter(eXFBorderSide, static_cast<float>(fWidth*0.5));
		pXFBorders->SetWidthInner(eXFBorderSide, static_cast<float>(fWidth*0.25));
		pXFBorders->SetWidthSpace(eXFBorderSide, static_cast<float>(fWidth*0.25));
		break;
	case 0x19: //thin-thick
		pXFBorders->SetDoubleLine(eXFBorderSide, sal_True, sal_False);
		pXFBorders->SetWidthInner(eXFBorderSide, static_cast<float>(fWidth*0.7));
		pXFBorders->SetWidthOutter(eXFBorderSide, static_cast<float>(fWidth*0.15));
		pXFBorders->SetWidthSpace(eXFBorderSide, static_cast<float>(fWidth*0.15));
		break;
	}

	if (aColor.IsValidColor())
	{
		XFColor aXFColor(aColor.To24Color());
		pXFBorders->SetColor(eXFBorderSide, aXFColor );
	}
}

void LwpParaStyle::ApplyParaBorder(XFParaStyle* pParaStyle, LwpParaBorderOverride* pBorder)
{
	//convert LwpShadow:
	LwpShadow *pShadow = pBorder->GetShadow();
	if( pShadow )
	{
		LwpColor color = pShadow->GetColor();
		float	offsetX = pShadow->GetOffsetX();
		float	offsetY = pShadow->GetOffsetY();

		if( offsetX && offsetY && color.IsValidColor() )
		{
			XFColor aXFColor(color.To24Color());
			sal_Bool left = sal_False;
			sal_Bool top = sal_False;
			if( offsetX < 0 )
				left = sal_True;
			if( offsetY < 0 )
				top = sal_True;
			if( left )
			{
				if( top )
					pParaStyle->SetShadow(enumXFShadowLeftTop,-offsetX,aXFColor);
				else
					pParaStyle->SetShadow(enumXFShadowLeftBottom,-offsetX,aXFColor);
			}
			else
			{
				if( top )
					pParaStyle->SetShadow(enumXFShadowRightTop,offsetX,aXFColor);
				else
					pParaStyle->SetShadow(enumXFShadowRightBottom,offsetX,aXFColor);
			}
		}
	}
	
	//convert to XFBorders obejct:
	LwpBorderStuff	*pBorderStuff = pBorder->GetBorderStuff();
	if( pBorderStuff && pBorderStuff->GetSide() != 0 )
	{			
		XFBorders	*pXFBorders = new XFBorders();
		pParaStyle->SetBorders(pXFBorders);

		LwpMargins* pMargins = pBorder->GetMargins();
		
		// apply 4 borders respectively
		LwpBorderStuff::BorderType pType[] = { LwpBorderStuff::LEFT, LwpBorderStuff::RIGHT,
			LwpBorderStuff::TOP, LwpBorderStuff::BOTTOM };
		float pMarginValue[4];
		
		for (sal_uInt8 nC = 0; nC < 4; nC++)
		{
			if (pBorderStuff->HasSide(pType[nC]))
			{
				this->ApplySubBorder(pBorderStuff, pType[nC], pXFBorders);

				//get border spacing to text content
				if (pMargins)
				{
					pMarginValue[nC] = static_cast<float>(pMargins->GetMarginsValue(nC));
				}
			}

		}

		//apply border spacing to text content
		pParaStyle->SetPadding(pMarginValue[0], pMarginValue[1], pMarginValue[2], pMarginValue[3]);
		
	}
}

void LwpParaStyle::ApplyBreaks(XFParaStyle* pParaStyle, LwpBreaksOverride* pBreaks)
{
	if (pBreaks->IsKeepWithNext())
	{
		pParaStyle->SetBreaks(enumXFBreakKeepWithNext);
	}
	if (pBreaks->IsPageBreakBefore())
	{
		pParaStyle->SetBreaks(enumXFBreakBefPage);
	}
	if (pBreaks->IsPageBreakAfter())
	{
		pParaStyle->SetBreaks(enumXFBreakAftPage);
	}
	if (pBreaks->IsColumnBreakBefore())
	{
		pParaStyle->SetBreaks(enumXFBreakBefColumn);
	}
	if (pBreaks->IsColumnBreakAfter())
	{
		pParaStyle->SetBreaks(enumXFBreakAftColumn);
	}
}

void LwpParaStyle::ApplyAlignment(XFParaStyle* pParaStyle, LwpAlignmentOverride* pAlign)
{
    enumXFAlignType alignType = enumXFAlignStart;
    LwpAlignmentOverride::AlignType type;
        
	type = pAlign->GetAlignType();
	pParaStyle->SetNumberRight(sal_False);//to identify its align attribute
	switch(type)
	{
	case LwpAlignmentOverride::ALIGN_LEFT:
		alignType = enumXFAlignStart;
		break;
	case LwpAlignmentOverride::ALIGN_RIGHT:
		alignType = enumXFAlignEnd;
		break;
	case LwpAlignmentOverride::ALIGN_CENTER:
		alignType = enumXFAlignCenter;
		break;
	case LwpAlignmentOverride::ALIGN_NUMERICLEFT://if non-number in table,ALIGN_NUMERICLEFT/RIGHT are useless
		alignType = enumXFAlignStart;            //note by  1/28
		break;
	case LwpAlignmentOverride::ALIGN_JUSTIFY:
	case LwpAlignmentOverride::ALIGN_JUSTIFYALL:
		alignType = enumXFAlignJustify;	    
		break;
	case LwpAlignmentOverride::ALIGN_NUMERICRIGHT:
		pParaStyle->SetNumberRight(sal_True);//to identify its align attribute
		alignType = enumXFAlignEnd;	
		break;
	}
	pParaStyle->SetAlignType(alignType);    
}

void LwpParaStyle::ApplyIndent(LwpPara* pPara, XFParaStyle* pParaStyle, LwpIndentOverride* pIndent)
{
	LwpPara* pParentPara;
	if (pPara)
		pParentPara = pPara->GetParent();
	else
		pParentPara = NULL;
		
	LwpIndentOverride* pTotalIndent = new LwpIndentOverride;		
	if (pIndent->IsUseRelative() && pParentPara)
	{
		LwpIndentOverride* pParentIndent = pParentPara->GetIndent();
		if (!pParentIndent)
			return;
		*pTotalIndent = *pIndent;
	
		//add by ,for bullet only
		if (pPara)
		{
			if (pPara->GetBulletFlag())
			{	
				pTotalIndent->SetMAll(pParentIndent->GetMAll() + pTotalIndent->GetMAll());
				pTotalIndent->SetMRight(pParentIndent->GetMRight()+ pTotalIndent->GetMRight());				
				pParaStyle->SetMargins(LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(
					pTotalIndent->GetMAll())), pTotalIndent->GetRight());
				pPara->SetIndent(pTotalIndent);					
				return;
			}
		}
		//end add
		sal_uInt16 relative = pParentIndent->GetRelative();
		
		sal_Int32 Amount = pParentIndent->GetMAll();
		
		if (relative == LwpIndentOverride::RELATIVE_FIRST)
			Amount += pParentIndent->GetMFirst();
		else if (relative == LwpIndentOverride::RELATIVE_REST)
			Amount += pParentIndent->GetMRest();
		pTotalIndent->SetMAll(Amount + pTotalIndent->GetMAll());
		pTotalIndent->SetMRight(pParentIndent->GetMRight()+ pTotalIndent->GetMRight());
		
		pParaStyle->SetIndent(pTotalIndent->GetFirst());
		pParaStyle->SetMargins(pTotalIndent->GetLeft(), pTotalIndent->GetRight());	
		pPara->SetIndent(pTotalIndent);	

	}
	else
	{
		*pTotalIndent = *pIndent;	
		//add by 
		if (pPara)
		{
			if (pPara->GetBulletFlag())
			{
//				pParaStyle->SetIndent(LwpTools::ConvertFromUnits(pIndent->GetMAll()));
				pParaStyle->SetMargins(LwpTools::ConvertToMetric(
					LwpTools::ConvertFromUnits(pIndent->GetMAll())), pIndent->GetRight());
				pPara->SetIndent(pTotalIndent);
				return;			
			}
		}
		//end add

		pParaStyle->SetIndent(pIndent->GetFirst());
		pParaStyle->SetMargins(pIndent->GetLeft(), pIndent->GetRight());
		if (pPara)
		{
			pPara->SetIndent(pTotalIndent);
		}
	}    
}

void LwpParaStyle::ApplySpacing(LwpPara* pPara, XFParaStyle* pParaStyle, LwpSpacingOverride* pSpacing)
{
    LwpSpacingCommonOverride* spacing = pSpacing->GetSpacing();
    LwpSpacingCommonOverride* aboveline = pSpacing->GetAboveLineSpacing();
    LwpSpacingCommonOverride* abovepara = pSpacing->GetAboveSpacing();
    LwpSpacingCommonOverride* belowpara = pSpacing->GetBelowSpacing();         
    
    LwpSpacingCommonOverride::SpacingType type = spacing->GetType();
    sal_Int32 amount = spacing->GetAmount();
    sal_Int32 multiple = spacing->GetMultiple();
    enumLHType xftype;
    double height;
  
    switch(type)
    {
    case LwpSpacingCommonOverride::SPACING_DYNAMIC:
    {
	xftype = enumLHPercent;
	height = double(multiple)/65536L*100;
	pParaStyle->SetLineHeight(xftype,height);  
    }
        break;
    case LwpSpacingCommonOverride::SPACING_LEADING:
    {
	xftype = enumLHSpace;
	height = LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(amount));
	pParaStyle->SetLineHeight(xftype,height);  
    }
        break;
    case LwpSpacingCommonOverride::SPACING_CUSTOM:
    {
	xftype = enumLHHeight;
	height =  LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(sal_Int32(float(multiple)/65536L*amount)));
    	pParaStyle->SetLineHeight(xftype,height);  
	}
        break;
    case LwpSpacingCommonOverride::SPACING_NONE:
        break; 
    }
      
//TO DO: Above Line need to be processed!!!!!!! what it means??????  1-26    
    
    type = abovepara->GetType();
    amount = abovepara->GetAmount();
    multiple = abovepara->GetMultiple();
    double above_val =-1;
    switch(type)
    {
    case LwpSpacingCommonOverride::SPACING_DYNAMIC:
//        above_val = LINE_HEIGHT*float(multiple)/65536L*100; //TO DO:  1-26 
        break;
    case LwpSpacingCommonOverride::SPACING_LEADING:
        break;
    case LwpSpacingCommonOverride::SPACING_CUSTOM:
        above_val =  LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(sal_Int32(float(multiple)/65536L*amount)));
        break;
    case LwpSpacingCommonOverride::SPACING_NONE:
        break; 
    }
        
    type = belowpara->GetType();
    amount = belowpara->GetAmount();
    multiple = belowpara->GetMultiple();    
    double below_val=-1; 
    switch(type)
    {
    case LwpSpacingCommonOverride::SPACING_DYNAMIC:
//        below_val = LINE_HEIGHT*float(multiple)/65536L*100;//TO DO:  1-26 
        break;
    case LwpSpacingCommonOverride::SPACING_LEADING:
        break;
    case LwpSpacingCommonOverride::SPACING_CUSTOM:
        below_val =  LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(sal_Int32(float(multiple)/65536L*amount)));
        break;
    case LwpSpacingCommonOverride::SPACING_NONE:
        break; 
    }
  
    if (pPara)
    {
    	if (below_val != -1)
    		pPara->SetBelowSpacing(below_val);
    	LwpPara* pPrePara = static_cast<LwpPara*>(pPara->GetPrevious()->obj());
    	if (pPrePara && above_val != -1)
    	{
    		above_val += pPrePara->GetBelowSpacing();
    		
    	}
    	
    }
    pParaStyle->SetMargins(-1,-1,above_val,below_val);    
}
/**************************************************************************
 * @short:   
 * @descr:  
 * @param:   
 * @param:   
 * @return:  
**************************************************************************/
void LwpParaStyle::ApplyTab(XFParaStyle *pParaStyle, LwpTabOverride *pTab)
{
	LwpObjectID* pTabRackID = pTab->GetTabRackID();
	if(pTabRackID->IsNull())
	{
		//assert(false);
		return;
	}

	LwpTabRack* pTabRack = static_cast<LwpTabRack*>(pTabRackID->obj());
	if(!pTabRack)
	{
		//assert(false);
		return;
	}
	
	pParaStyle->ClearTabStyles();
	//Get margin left value
	double dMarginLeft = pParaStyle->GetMargins().GetLeft();
	
	sal_uInt16 nNumTabs = pTabRack->GetNumTabs();
	for(sal_uInt16 nIndex=0; nIndex<nNumTabs; nIndex++)
	{
		//get tab type
		LwpTab* pTab = pTabRack->Lookup(nIndex);
		if(!pTab)
			return;

		enumXFTab eType;
		LwpTab::TabType type = pTab->GetTabType();
		switch(type)
		{
		case LwpTab::TT_LEFT:
			eType = enumXFTabLeft;
			break;
		case LwpTab::TT_CENTER:
			eType = enumXFTabCenter;
			break;
		case LwpTab::TT_RIGHT:
			eType = enumXFTabRight;
			break;
		case LwpTab::TT_NUMERIC:
			eType = enumXFTabChar;
			break;
		}
		
		//get position
		sal_uInt32 nPos = pTab->GetPosition();
		//different feature between SODC and lwp, the tab length must minus the margin left of para.
		double fLen = LwpTools::ConvertFromUnitsToMetric(nPos) - dMarginLeft;
		
		//get leader type
		sal_Unicode cLeader;
		LwpTab::LeaderType leader= pTab->GetLeaderType();
		switch(leader)
		{
		case LwpTab::TL_NONE:
			cLeader = 0x20;		//space
			break;
		case LwpTab::TL_HYPHEN:	//'-'
			cLeader = 0xAD;		
			break;
		case LwpTab::TL_DOT:	//'.'
			cLeader = 0x2E;
			break;
		case LwpTab::TL_LINE:	//'_'
			cLeader = 0x5F;
			break;
		}

		sal_Unicode cAlignChar = static_cast<sal_Unicode>(pTab->GetAlignChar());		

		pParaStyle->AddTabStyle(eType,fLen,cLeader,cAlignChar);	
	}
	
}


void LwpParaStyle::RegisterStyle()
{
	XFParaStyle* pStyle = new XFParaStyle();

	//Set name
	OUString styleName = GetName()->str();
	pStyle->SetStyleName(styleName);
	
	//Create font
	LwpFontManager* pFontMgr = m_pFoundry->GetFontManger();
	XFFont* pFont = pFontMgr->CreateFont(m_nFinalFontID);
	pStyle->SetFont(pFont);
	
	//Set other paragraph properties...

	Apply(pStyle);
	//Add style
	LwpStyleManager* pStyleMgr = m_pFoundry->GetStyleManager();
	pStyleMgr->AddStyle(*GetObjectID(), pStyle);

/*	// add list style for bullet
	if (!m_pBulletOverride)
	{
		return;
	}
	LwpSilverBullet* pSilverBullet = static_cast<LwpSilverBullet*>(m_pBulletOverride->GetSilverBullet().obj());
	if (!pSilverBullet)
	{
		return;
	}

	pSilverBullet->SetFoundry(m_pFoundry);
	pSilverBullet->RegisterStyle();*/
}

LwpAlignmentOverride* LwpParaStyle::GetAlignment()
{
    if (m_AlignmentStyle.obj()!= NULL)
        return static_cast<LwpAlignmentOverride*>(static_cast<LwpAlignmentPiece*>(m_AlignmentStyle.obj())->GetOverride());
    else
        return NULL;
}

LwpIndentOverride* LwpParaStyle::GetIndent()
{
    if (m_IndentStyle.obj() != NULL)
        return static_cast<LwpIndentOverride*>(static_cast<LwpIndentPiece*>(m_IndentStyle.obj())->GetOverride());
    else
        return NULL;
}

LwpSpacingOverride* LwpParaStyle::GetSpacing()
{
    if (m_SpacingStyle.obj() != NULL)
        return static_cast<LwpSpacingOverride*>(static_cast<LwpSpacingPiece*>(m_SpacingStyle.obj())->GetOverride());
    else
        return NULL;
}

LwpParaBorderOverride* LwpParaStyle::GetParaBorder() const
{
	if(m_BorderStyle.IsNull()) return NULL;
	return static_cast<LwpParaBorderOverride*>
		(static_cast<LwpParaBorderPiece*>(m_BorderStyle.obj(VO_PARABORDERPIECE))->GetOverride());
}

LwpBreaksOverride* LwpParaStyle::GetBreaks() const
{
	if(m_BreaksStyle.IsNull()) return NULL;
	return static_cast<LwpBreaksOverride*>
		(static_cast<LwpBreaksPiece*>(m_BreaksStyle.obj(VO_BREAKSPIECE))->GetOverride());
}

LwpBulletOverride* LwpParaStyle::GetBulletOverride() const
{
	return m_pBulletOverride;
}

LwpNumberingOverride* LwpParaStyle::GetNumberingOverride() const
{
	if(m_NumberingStyle.IsNull()) return NULL;
	return static_cast<LwpNumberingOverride*>
		(static_cast<LwpNumberingPiece*>(m_NumberingStyle.obj(VO_NUMBERINGPIECE))->GetOverride());
}


/**************************************************************************
 * @short:   
 * @descr:  
 * @param:   
 * @param:   
 * @return:  
**************************************************************************/
LwpTabOverride* LwpParaStyle::GetTabOverride() const
{
	if(m_TabStyle.obj() != NULL)
		return (LwpTabOverride*)static_cast<LwpTabPiece*>(m_TabStyle.obj())->GetOverride();
	else
		return NULL;
}

sal_Bool LwpParaStyle::IsNumberRight()
{
	LwpAlignmentOverride* pAlign = GetAlignment();
	if (pAlign)
	{
		LwpAlignmentOverride::AlignType type; 
		type = pAlign->GetAlignType();
		if (type == LwpAlignmentOverride::ALIGN_NUMERICRIGHT)
			return sal_True;	
	}
	return sal_False;
}